export const initState = {
    //用户信息
    info: sessionStorage.getItem("info") ? JSON.parse(sessionStorage.getItem("info")) : {}
}

export const reducer = (state, action) => {
    switch (action.type) {
        //修改info的逻辑
        case "changeInfo":
            return {
                ...state,
                info: action.info
            }
            break;
        default:
            return state;
    }
}

export const actions={
    changeInfo:(info)=>{
        //同步本地存储
        if(info.token){
            sessionStorage.setItem("info",JSON.stringify(info))
        }else{
            sessionStorage.removeItem("info")
        }
        return {type:"chanfeINfo",info}
    }
}